import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import '../../../../app_files.dart';
import 'action.dart';
import 'state.dart';
import '../../model/account_model.dart';

Widget buildView(GasNoSearchResultViewState state, Dispatch dispatch,
    ViewService viewService) {
  Widget _buildItem(BuildContext context, int index) {
    AccountItemModel item = state.items[index];

    return GestureDetector(
      child: Container(
        height: 70,
        margin: EdgeInsets.only(
          top: 10,
        ),
        padding: EdgeInsets.symmetric(horizontal: 15),
        color: Colors.white,
        child: Row(
          children: <Widget>[
            Image.asset('images/icon_gas.png'),
            Expanded(
              child: Container(
                padding: EdgeInsets.only(left: 20),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Text(
                      item.accountNo,
                      style: TextThemeConfig.Font14WithColor22,
                    ),
                    Padding(padding: EdgeInsets.only(top: 4)),
                    Text(
                      '${item.name}  |  ${item.address}',
                      style: TextThemeConfig.Font14WithColor99,
                      maxLines: 1,
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
      onTap: () => dispatch(GasNoSearchResultViewActionCreator.onTap(item)),
    );
  }

  return Scaffold(
    appBar: myAppBar(viewService.context, title: '查询结果'),
    body: state.isEmpty
        ? Center(child: MyEmptyItemWidget(
      desc: '未查询到客户信息',
      image: 'images/no_order.png',
    ),)
        : ListView.builder(
            itemBuilder: _buildItem,
            itemCount: state.items.length,
          ),
  );
}
